<template>
  <!-- 1. 顶部定位 -->
  <div class="wrapBox">
    <van-nav-bar
      title="专题详情"
      left-arrow
      fixed
      @click-left="$emit('input', false)"
    />
    <!-- 2. 占位元素 -->
    <div class="zhanwei"></div>
    <!-- 3.图片内容 -->
    <div class="con">
      <div v-html="imgs" class="boxImg"></div>
    </div>
    <!-- 4.评论内容: -->
    <div class="leanCon" >
      <span>精选留言</span>
      <van-icon name="more-o" @click="isShowDetailPost = true" />
    </div>
    <!-- 5.留言内容渲染 -->
    <div class="lean-box">
      <van-cell-group v-for="obj in leaningMsgData" :key="obj.id">
        <van-cell :value="obj.add_time">
          <div slot="title">
            <img class="" :src="obj.user_info.avatar" alt="" />
            <span class="topicName">{{ obj.user_info.nickname }}</span>
          </div>
        </van-cell>
        <p class="text-content">{{ obj.content }}</p>
      </van-cell-group>
    </div>

    <!-- 发布评论组件 -->
    <!-- <detailPost v-if="isShowDetailPost"  v-model="isShowDetailPost"  class="fixed"></detailPost> -->
    <detailPost
      v-if="isShowDetailPost"
      :Vid="id"
      @changeIsShowDetailPost="isShowDetailPost = $event"
      class="fixed"
    ></detailPost>
    <!-- changeIsShowDetailPost -->

    <!-- 展示更多 -->
    <div class="moreComment" @click="isShowAllData = true">
     展示更多评论内容...
    </div>
    <showAllComment
      class="Comment-cover"
      v-model="isShowAllData"
      v-if="isShowAllData"
      :id="id"
    ></showAllComment>
  </div>
</template>

<script>
import { specialDetail, leaningMsg, getCommentCount } from "@/api/special";
import detailPost from "./detailPost.vue";
import showAllComment from "./showAllComment.vue";
export default {
  name: "DetailPage",
  data() {
    return {
      imgs: "", //图片列表
      avatar: "", //头像地址
      leaningMsgData: [], //评论列表
      isShowDetailPost: false,
      allCountObj: {},
      isShowAllData: false,
    };
  },
  components: {
    detailPost,
    showAllComment,
  },
  props: {
    id: Number,
    value: {
      type: Boolean,
    },
  },
  created() {
    //1. 获取专题详情数据
    this.specialDetailHandler();
    // 2.获取评论详情
    this.leaningMsgHandler();
    // 获取总条数
    this.getCommentCountHandler();
  },
  methods: {
    async specialDetailHandler() {
      //   this.$toast.loading({
      //     message: "加载中...",
      //     forbidClick: true, // 禁用背景点击
      //     duration: 0, // 持续时间，默认 2000，0 表示持续展示不关闭
      //   });

      try {
        const { data } = await specialDetail({ id: this.id });
        this.imgs = data.data.content;

        this.avatar = data.data.avatar; //留着头像图片;

        // this.$toast.success("加载成功!");
        if (data.errno !== 0) {
          this.$toast.message("数据发送成功,但请求数据失败!");
        }
      } catch (err) {
        console.log(err.message);
      }
    },

    //    获取留言列表
    async leaningMsgHandler() {
      const { data } = await leaningMsg({
        valueId: this.id,
        typeId: 1,
        page: 1,
        size: 5,
        showType: 0,
      });
      this.leaningMsgData = data.data.data;
    },
    // 获取留言总条数;
    async getCommentCountHandler() {
      const res = await getCommentCount({
        valueId: this.id,
        typeId: 1,
      });
      this.allCountObj = { ...res.data.data };

    },
  },
};
</script>

<style scoped lang="scss">
::v-deep .van-nav-bar__content {
  background-color: rgb(225, 28, 52);
}
::v-deep .van-icon-arrow-left {
  color: #fff !important;
}

.wrapBox {
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  //   一定要要加背景色 否則透明
  background-color: #fff;
  z-index: 2;
  overflow-y: auto;
}

.zhanwei {
  height: 92px;
}
.con {
  // width: 100vw !important;
  .boxImg {
    display: flex;
    flex-direction: column;
    width: 100vw !important;
  }
  img {
    width: 100vw !important;
  }
}
// ==========
.leanCon {
  display: flex;
  justify-content: space-between;
  padding: 20px 30px;
  font-size: 32px;
}
.lean-box {
  img {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    vertical-align: middle;
  }
  .topicName {
    padding: 0 15px;
  }
}
.text-content {
  font-size: 24px;
  color: #999;
  padding: 20px 30px;
  line-height: 40px;
}

.fixed {
  position: fixed;
  width: 100vw;
  height: 100vh;
  top: 0;
  left: 0;
  z-index: 3;
  box-sizing: border-box;
}

.moreComment {
  height: 80px;
  text-align: center;
  font-size: 28px;
  color: #666;
  display: flex;
  justify-content: center;
  align-items: center;
}
.Comment-cover {
  position: fixed;
  width: 100vw;
  height: 100vh;
  left: 0;
  top: 0;
  z-index: 100;
  background-color: #fff;
}
</style>
